package eu.fishcode.android.ui.component;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JToolBar.Separator;

import eu.fishcode.android.utils.Utils;

public class Dialog extends JDialog {

	private static final long serialVersionUID = 1111111100000000112L;
	private final Header header;
	public JPanel footer;
	public JButton close;

	public Dialog() {
		this.setTitle(Utils.getLabel("title"));
		this.setLayout(new BorderLayout());

		this.header = new Header();
		this.footer = new JPanel();

		this.close = new JButton(Utils.getLabel("close"));
		this.close.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent event) {
				Dialog.this.dispose();
			}
		});

		this.footer.setLayout(new BorderLayout());
		this.footer.add(new Separator(), BorderLayout.PAGE_START);
		this.footer.add(this.close, BorderLayout.LINE_END);

		this.add(this.header, BorderLayout.PAGE_START);
		this.add(this.footer, BorderLayout.PAGE_END);

		this.setModalityType(ModalityType.APPLICATION_MODAL);
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		this.setSize(450, 400);
	}

	public void setDescription(String description) {
		this.header.setDescription(description);
	}

	public void setIcon(ImageIcon image) {
		this.header.setIcon(image);
	}

	@Override
	public void setTitle(String title) {
		if (this.header == null) {
			super.setTitle(title);
		} else {
			this.header.setTitle(title);
		}
	}
}
